import request from '@/utils/request'

export interface Role {
  id?: number;
  name: string;
  code: string;
  description: string;
}

export interface QueryRole {
  id?: string;
  name?: string;
  code?: string;
  current?: number;
  size?: number;
  startCreateTime?: string;
  endCreateTime?: string;
}

export const getRolePages = (data: QueryRole) => {
  return request({
    method: 'POST',
    url: '/boss/role/getRolePages',
    data
  })
}

export const createOrUpdateRole = (data: Role) => {
  return request({
    method: 'POST',
    url: '/boss/role/saveOrUpdate',
    data
  })
}

export const getRoleById = (id: number | string) => {
  return request({
    method: 'GET',
    url: `/boss/role/${id}`
  })
}

export const deleteRole = (id: number | string) => {
  return request({
    method: 'DELETE',
    url: `/boss/role/${id}`
  })
}

export const getAllRoles = () => {
  return request({
    method: 'GET',
    url: '/boss/role/all'
  })
}

export const allocateUserRoles = (data: {userId: string; roleIdList: string[]}) => {
  return request({
    method: 'POST',
    url: '/boss/role/allocateUserRoles',
    data
  })
}
export const getUserRoles = (userId: string | number) => {
  return request({
    method: 'GET',
    url: `/boss/role/user/${userId}`
  })
}
